home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
yahoo
/
YahooSocket.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
6KB
|
199 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
DEFAULT_YMSG_VERSION = 15
from yahoo.yahooutil import *
from util import to_storage, unpack_named, dictargcall, traceguard
import common
from pprint import pformat
import sys
import traceback
from logging import getLogger
log = getLogger('yahoo')
loginlog = getLogger('yahoo.login')
packets_log = getLogger('yahoo.packets')
class YahooSocket(common.socket):
def __init__(self, yahoo, server):
common.socket.__init__(self)
self.yahoo = yahoo
self.session_id = 0
self.active_gens = { }
self.set_terminator(header_size)
self.getting_header = True
self.data = []
self.byte_count = 0
self.server = server
def __str__(self):
return 'YahooSocket(%s:%d, %d bytes in)' % (self.server[0], self.server[1], self.byte_count)
def make_ypacket(self, service, status, version = DEFAULT_YMSG_VERSION, data = ''):
if not isinstance(service, (int, long)):
raise TypeError('service is', service, 'but should be an int!')
if not isinstance(status, (int, long)):
raise TypeError('status is', status, 'but should be an int!')
return pack(header_pack, 'YMSG', version, 0, len(data), service, status, self.session_id) + data
def ysend(self, service, status, version = DEFAULT_YMSG_VERSION, data = ''):
packet = self.make_ypacket(service, status, version, data)
self.push(packet)
def handle_packet(self, header, data):
self.session_id = header.session_id
if (header.service, header.status) in self.active_gens:
gen = self.active_gens.pop((header.service, header.status))
self.async_proc(gen, header, data)
return None
sv_str = services.get(header.service, '')
st_str = statuses.get(header.status, '')
target = self.yahoo
fnname = '%s_%s' % (sv_str, st_str)
traceguard.__enter__()
try:
packet_str = format_packet(data, sensitive = not getattr(sys, 'DEV', True))
packets_log.debug('~~> %s\n%s', fnname, packet_str)
finally:
pass
raw_fn = '%s_raw' % fnname
if hasattr(target, raw_fn):
try:
return getattr(target, raw_fn)(from_ydict_iter(data))
except Exception:
traceguard
traceguard
traceback.print_exc()
except:
traceguard
finally:
return None
if sv_str and st_str:
fn = '%s_%s' % (sv_str, st_str)
if hasattr(target, fn):
func = getattr(target, fn)
try:
return dictargcall(func, from_ydict(data), ykeys)
except Exception:
traceback.print_exc()
print >>sys.stderr, ' File "%s", line %d, in %s' % (func.func_code.co_filename, func.func_code.co_firstlineno, func.func_name)
return None
except:
None<EXCEPTION MATCH>Exception
None<EXCEPTION MATCH>Exception
unhandled_text = None([
None,
''.join,
'unhandled packet: ' if sv_str else str(header.service),
'_' if st_str else str(header.status)])
log.warning('%s:::%r', unhandled_text, data)
def async_proc(self, gen, header = None, data = None):
try:
args = None if not header else (header, data)
(cmd, wait_on, packet) = gen.send(args)
while cmd == 'send':
self.push(packet)
(cmd, wait_on, packet) = gen.next()
if cmd == 'wait':
self.active_gens[wait_on] = gen
except StopIteration:
pass
except YahooLoginError:
self.yahoo.set_disconnected(self.yahoo.Reasons.BAD_PASSWORD)
def gsend(self, sv, st, data = '', **kwargs):
if 'v' not in kwargs:
v = DEFAULT_YMSG_VERSION
else:
v = kwargs['v']
if isinstance(sv, str):
sv = services[sv]
if isinstance(st, str):
st = statuses[st]
if isinstance(data, (dict, list)):
data = to_ydict(data)
packet = self.make_ypacket(sv, st, v, data)
return ('send', None, packet)
def gwait(self, sv, st, err_fn):
sv = services[sv]
st = statuses[st]
return ('wait', (sv, st), err_fn)
def __repr__(self):
return '<%s(%s:%d) - sId: %s, bytes in: %d>' % (self.__class__.__name__, self.server[0], self.server[1], self.session_id, self.byte_count)
def handle_connect(self):
raise NotImplementedError
def handle_close(self):
raise NotImplementedError
def collect_incoming_data(self, data):
self.data.append(data)
self.byte_count += len(data)
def handle_error(self, *a, **k):
traceback.print_exc()
raise NotImplementedError
def handle_expt(self):
raise NotImplementedError
def found_terminator(self):
datastr = ''.join(self.data)
if self.getting_header:
self.getting_header = False
self.header = to_storage(unpack_named(*header_desc + tuple([
datastr])))
if self.header.ymsg != 'YMSG' or self.header.size < 0:
return log.warning('invalid packet')
if self.header.size > 0:
self.set_terminator(self.header.size)
else:
self.getting_header = True
self.set_terminator(header_size)
self.handle_packet(self.header, datastr)
self.data = []
else:
self.getting_header = True
self.set_terminator(header_size)
self.handle_packet(self.header, datastr[header_size:])
self.data = []